﻿using Tisbi.LawFirm.BL.Services;
using Tisbi.LawFirm.DAL.Models;
using Tisbi.LawFirm.UI.Views.Controls.Forms;

namespace Tisbi.LawFirm.UI.ViewModel
{
    public class DistrictViewModel : BaseViewModel<District, IServiceAgentBase<District>>
    {
        protected override void LoadModelBySearch()
        {
            IsBusy = true;

            ModelServiceAgent.GetItem
                (
                    (list, exception) =>
                        ModelLoadedByWhere(list, exception, item => item.Title.Contains(SearchCriteria))
                );
        }

        protected override void ShowEditDialog()
        {
            if (SelectedModelItem == null)
            {
                return;
            }

            var model = new DistrictCRUDViewModal(SelectedModelItem);
            ShowEditDialog<DistrictCRUDForm>(model, "Карточка изменения федерального округа");
        }

        protected override void ShowCreatedDialog()
        {
            var newItem = new District();
            var detailModel = new DistrictCRUDViewModal(newItem);

            ShowCreatedDialog<DistrictCRUDForm>(detailModel, "Карточка создания нового федерального округа");
        }
    }
}
